
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the File table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.File_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Url nvarchar (200)  = null ,

	@Title nvarchar (50)  = null ,

	@ParentId nvarchar (20)  = null ,

	@OrderIndex int   = null ,

	@IsPublished bit   = null ,

	@FileType varchar (10)  = null ,

	@CreatedDate datetime   = null ,

	@UpdatedDate datetime   = null ,

	@CreatedUser varchar (50)  = null ,

	@UpdatedUser varchar (50)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Url]
	, [Title]
	, [ParentId]
	, [OrderIndex]
	, [IsPublished]
	, [FileType]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
    FROM
	[dbo].[File]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Url] = @Url OR @Url IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([ParentId] = @ParentId OR @ParentId IS NULL)
	AND ([OrderIndex] = @OrderIndex OR @OrderIndex IS NULL)
	AND ([IsPublished] = @IsPublished OR @IsPublished IS NULL)
	AND ([FileType] = @FileType OR @FileType IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([UpdatedDate] = @UpdatedDate OR @UpdatedDate IS NULL)
	AND ([CreatedUser] = @CreatedUser OR @CreatedUser IS NULL)
	AND ([UpdatedUser] = @UpdatedUser OR @UpdatedUser IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Url]
	, [Title]
	, [ParentId]
	, [OrderIndex]
	, [IsPublished]
	, [FileType]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
    FROM
	[dbo].[File]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Url] = @Url AND @Url is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([ParentId] = @ParentId AND @ParentId is not null)
	OR ([OrderIndex] = @OrderIndex AND @OrderIndex is not null)
	OR ([IsPublished] = @IsPublished AND @IsPublished is not null)
	OR ([FileType] = @FileType AND @FileType is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([UpdatedDate] = @UpdatedDate AND @UpdatedDate is not null)
	OR ([CreatedUser] = @CreatedUser AND @CreatedUser is not null)
	OR ([UpdatedUser] = @UpdatedUser AND @UpdatedUser is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
